package com.hulushuju.core.security.ssl;

import lombok.var;

import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.*;
import java.io.*;
import java.security.*;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.Objects;

/**
 * @Author: Hanjiafeng
 * @Date: 2019-05-21
 * @Desc: 证书加载类
 */
public class SSLSocketFactoryCreator {

    /**
     * 获取SSLSocketFactory
     *
     * @return SSLSocketFactory
     * @throws NoSuchAlgorithmException 算法错误
     * @throws KeyManagementException   键错误
     */
    public static SSLSocketFactory createSSLSocketFactory(TrustManager[] trustManagers) throws NoSuchAlgorithmException, KeyManagementException {
        //获取加密算法实例
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, trustManagers, new SecureRandom());

        return sslContext.getSocketFactory();
    }
}
